home *** CD-ROM | disk | FTP | other *** search
- /*
- * gen_dt_i.c
- *
- * Practical Algorithms for Image Analysis
- *
- * Copyright (c) 1997, 1998, 1999 MLMSoftwareGroup, LLC
- */
-
- /*
- * GEN_DT_IO
- *
- * generic modules to read data file of type .adt, .pdt, etc
- * and write data file of type *.aft (same as *.pft) for plotting
- *
- */
- #include <stdio.h>
- #include <stdlib.h>
-
- #undef DEBUG
-
-
- #define STAT_WT 1.0
-
-
-
-
- /*
- * read first line in data file to determine size of record
- * (expects file of type .pdt, .adt, .azv, etc)
- */
- int
- get_record_size (file)
- FILE *file;
- {
- int retval, n_rec;
-
- if (((retval = fscanf (file, "%d ", &n_rec)) == 0) || (retval == EOF)) {
- printf ("wrong input file format!\n");
- exit (1);
- }
- return (n_rec);
- }
-
-
- int
- get_prm_size (file)
- FILE *file;
- {
- int retval, n_rec;
-
- if (((retval = fscanf (file, "%d ", &n_rec)) == 0) || (retval == EOF)) {
- printf ("wrong input file format!\n");
- exit (1);
- }
- return (n_rec);
- }
-
-
-
- /*
- * read data from file of type .pdt
- */
- void
- get_col2_data (file, n_parms, a, npts, x, y, sig)
- FILE *file;
- int n_parms, npts;
- float *a, *x, *y, *sig;
- {
- int i;
- int retval;
-
- /*
- * first, read starting values for fit parameters
- */
- for (i = 0; i < n_parms; i++) {
- if (((retval = fscanf (file, "%f", (a + i))) == 0) || (retval == EOF)) {
- printf ("wrong input file format for parameters!\n");
- exit (1);
- }
- #ifdef DEBUG
- printf ("...a[%d] = %f\n", i, *(a + i));
- #endif
- }
-
- /*
- * now read data;
- * -->note: mrqmin expects unit offset arrays
- */
- for (i = 0; i < npts; i++) {
- if ((retval = fscanf (file, "%f %f", (x + i), (y + i)) == 0) || (retval == EOF)) {
- printf ("wrong input file format for data points!\n");
- exit (1);
- }
- *(sig + i) = (float) STAT_WT;
- #ifdef DEBUG
- printf ("...x[%d] = %f, y[%d] = %f\n", i, *(x + i), i, *(y + i));
- #endif
- }
- }
-
-
- /*
- * read data from file of type .adt, .azv
- */
- void
- get_col3_data (file, n_parms, a, npts, x, oy, y, sig)
- FILE *file;
- int n_parms, npts;
- float *a, *x, *oy, *y, *sig;
- {
- int i;
- int retval;
-
- /*
- * first, read starting values for fit parameters
- */
- for (i = 0; i < n_parms; i++) {
- if (((retval = fscanf (file, "%f", (a + i))) == 0) || (retval == EOF)) {
- printf ("wrong input file format for parameters!\n");
- exit (1);
- }
- #ifdef DEBUG
- printf ("...a[%d] = %f\n", i, *(a + i));
- #endif
- }
-
- /*
- * now read data;
- * -->note: mrqmin expects unit offset arrays
- */
- for (i = 0; i < npts; i++) {
- if ((retval = fscanf (file, "%f %f %f", (x + i), (oy + i), (y + i)) == 0) || (retval == EOF)) {
- printf ("wrong input file format for data points!\n");
- exit (1);
- }
- *(sig + i) = (float) STAT_WT;
- #ifdef DEBUG
- printf ("\n...x[%d] = %f, oy[%d] = %f, y[%d] = %f\n",
- i, *(x + i), i, *(oy + i), i, *(y + i));
- #endif
- }
- }
-
-
-
-
- /*
- * write .adt file (to be read by acff.c)
- * same as .azv, .azd
- */
- void
- write_adt_file (file, x_data, y_data, acf, n_pts, n_parms)
- FILE *file;
- float *x_data, *y_data, *acf;
- int n_pts, n_parms;
- {
- float dummy = (float) 1.0;
- int i;
-
- fprintf (file, "%d %d\n", n_pts, n_parms);
-
- for (i = 0; i < n_parms; i++)
- fprintf (file, "%f\n", dummy);
-
- for (i = 0; i < n_pts; i++)
- fprintf (file, "%f %f %f\n", *(x_data + i), *(y_data + i), *(acf + i));
-
- fprintf (file, "\n");
-
- }
-
-
- /*
- * write data file of type .pft for plotting by pwr_plt.c
- */
- void
- write_pft_file (file, x, y, rsd, n_pts, x_fit, y_fit, n_fit,
- parameters, n_parms, chisq)
- FILE *file;
- float *x, *y, *rsd;
- float *x_fit, *y_fit;
- float *parameters;
- double chisq;
- int n_pts, n_fit, n_parms;
- {
- int i;
-
-
- fprintf (file, "%d %d %d\n", n_pts, n_fit, n_parms);
-
- for (i = 0; i < n_pts; i++)
- fprintf (file, "%f %f %f\n", *(x + i), *(y + i), *(rsd + i));
-
- for (i = 0; i < n_fit; i++)
- fprintf (file, "%f %f\n", *(x_fit + i), *(y_fit + i));
-
- fprintf (file, "%f\n", chisq);
-
- for (i = 0; i < n_parms; i++)
- fprintf (file, "%f\n", *(parameters + i));
-
- fprintf (file, "\n");
-
- }
-